﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Budgetsch.WP7.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;

namespace Budgetsch.WP7.ViewModel
{
    using System.Net;

    using Budgetsch.WP7.Design;
    using Budgetsch.WP7.Model.DataService;
    using Budgetsch.WP7.Model.Live;
    using Budgetsch.WP7.Navigation;
    using Budgetsch.WP7.Utils;
    using Budgetsch.WP7.ViewModel.Cost;
    using Budgetsch.WP7.ViewModel.Income;
    using Budgetsch.WP7.ViewModel.Public;
    using Budgetsch.WP7.ViewModel.Saving;
    using Budgetsch.WP7.ViewModel.Setting;

    using AuthenticationService = Budgetsch.WP7.Model.Live.AuthenticationService;

    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            SimpleIoc.Default.Register<AppSettings>();
            if (ViewModelBase.IsInDesignModeStatic)
            {
                SimpleIoc.Default.Register<IIncomeDataService, DesignIncomeDataService>();
            }
            else
            {
                SimpleIoc.Default.Register<CookieContainerViewModel>();
                SimpleIoc.Default.Register<IAuthenticationService, AuthenticationService>();
                SimpleIoc.Default.Register<IIncomeDataService, IncomeDataService>();
                SimpleIoc.Default.Register<ICostDataService, CostDataService>();
                SimpleIoc.Default.Register<ICommentDataService,CommentDataService>();
                SimpleIoc.Default.Register<ISavingDataService, SavingDataService>();
                SimpleIoc.Default.Register<IPublicDataService, PublicDataService>();
            }

            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<SavingViewModel>();
            SimpleIoc.Default.Register<SavingDetailsViewModel>();
            SimpleIoc.Default.Register<CostViewModel>();
            SimpleIoc.Default.Register<CostDetailsViewModel>();
            SimpleIoc.Default.Register<IncomeViewModel>();
            SimpleIoc.Default.Register<IncomeDetailsViewModel>();
            SimpleIoc.Default.Register<INavigationService, NavigationService>();
            SimpleIoc.Default.Register<CommentWriterViewModel>();
            SimpleIoc.Default.Register<PublicViewModel>();
            SimpleIoc.Default.Register<PublicDashboardViewModel>();
            SimpleIoc.Default.Register<SettingsViewModel>();
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel MainViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public IncomeViewModel IncomeViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<IncomeViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public CostViewModel CostViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CostViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public SavingViewModel SavingViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<SavingViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
       

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public CookieContainer CookieContainer
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CookieContainer>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public IAuthenticationService AuthenticationService
        {
            get
            {
                return ServiceLocator.Current.GetInstance<IAuthenticationService>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public IncomeDetailsViewModel IncomeDetailsViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<IncomeDetailsViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public CostDetailsViewModel CostDetailsViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CostDetailsViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public SavingDetailsViewModel SavingDetailsViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<SavingDetailsViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public CommentWriterViewModel CommentWriterViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CommentWriterViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public PublicViewModel PublicViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PublicViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public PublicDashboardViewModel PublicDashboardViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PublicDashboardViewModel>();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
        public SettingsViewModel SettingsViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<SettingsViewModel>();
            }
        }


        //
        

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
        }
    }
}